package com.amikomgamedev.panjatpinang.entities;

import org.andengine.entity.primitive.Rectangle;
import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.ui.activity.BaseGameActivity;

import android.content.Context;

import com.amikomgamedev.panjatpinang.Config;
import com.amikomgamedev.panjatpinang.Define;
import com.amikomgamedev.panjatpinang.Game;
import com.amikomgamedev.panjatpinang.Utils;

/*
 * AndEngineGamePanjatPinang
 * Entity_Mc.java
 * Pratama Wijaya
 * set.mnemonix@gmail.com
 * 4:03:29 PM , Jul 17, 2012
 */

public class Entity_Mc implements Define {

	public static int				CurrentPos		= MC_POS_RIGHT;
	public static int				CurrentState	= MC_STATE_BERDIRI;
	public static boolean			isSwap			= false;

	private static AnimatedSprite	AspMc;
	private float					CurX;
	private float					CurY;

	public Rectangle				RctMc;
	private static BaseGameActivity	activity;
	private static Context			context;

	private int						leftPosX;
	private int						rigthPosX;

	public float					getRctX;

	public Entity_Mc(AnimatedSprite spr, Context con, float curX, float curY) {
		context = con;
		activity = (BaseGameActivity) con;

		this.AspMc = spr;
		this.CurX = curX;
		this.CurY = curY;

		RctMc = new Rectangle(AspMc.getX() + (Define.GAME_SCREEN_WIDTH / 3),
				AspMc.getY() + (Define.GAME_SCREEN_HEIGHT / 13),
				(AspMc.getWidth()) - (AspMc.getWidth() / 3),
				(AspMc.getHeight() / 3), activity.getEngine()
						.getVertexBufferObjectManager());
		RctMc.setVisible(false);
		// RctMc.setColor(255, 0, 250);
		AspMc.attachChild(RctMc);
		/*
		 * RctMc = new Rectangle(AspMc.getX() + (AspMc.getWidth() / 2),
		 * AspMc.getY(), AspMc.getWidth(), (AspMc.getHeight() / 2),
		 * activity.getEngine().getVertexBufferObjectManager());
		 * RctMc.setVisible(true); RctMc.setColor(255, 0, 250);
		 * AspMc.attachChild(RctMc);
		 */
		// set posisi MC
		CurrentPos = MC_POS_RIGHT;
		CurrentState = MC_STATE_BERDIRI;

		this.AspMc.setPosition(curX, curY);

	}

	public static void switchPosition(int Cur_Pos) {
		CurrentPos = Cur_Pos;
		isSwap = true;
		setAnim(1, 0);
	}

	public static void setMcPosition(int pos) {
		CurrentPos = pos;
		switch (CurrentPos) {
			case MC_POS_RIGHT:
				Utils.TRACE("cek tombol switch : pindah ke kanan");
				Game.FlipAspMainChar.setVisible(false);
				Game.AspMainchar.setVisible(true);
				break;
			case MC_POS_LEFT:
				Utils.TRACE("cek tombol switch : pindah ke kiri");
				Game.FlipAspMainChar.setVisible(false);
				Game.AspMainchar.setVisible(true);
				break;
		}
	}

	public void mcUpdate() {
		switch (CurrentPos) {
			case MC_POS_LEFT:
				if (isSwap && !AspMc.isAnimationRunning()) {
					AspMc.setFlippedHorizontal(true);
					AspMc.setPosition(leftPosX, CurY);
					CurX = leftPosX;
					AspMc.setFlippedHorizontal(true);
					setAnim(SPR_ANIME_IDLE, 0);
					isSwap = false;
					// RctMc = new
					// Rectangle((Config.GAME_SCREEN_WIDTH/2)-(Config.GAME_SCREEN_WIDTH/3),
					// AspMc.getY()-(AspMc.getY()/2),
					// (AspMc.getWidth())-(AspMc.getWidth()/3),
					// (AspMc.getHeight()/10),
					// activity.getEngine().getVertexBufferObjectManager());
					// RctMc.setVisible(true);
					// RctMc.setColor(255, 0, 250);
					// AspMc.attachChild(RctMc);
					RctMc.setX((AspMc.getX() / 2) - (AspMc.getX() / 2));
				}
				break;
			case MC_POS_RIGHT:
				if (isSwap && !AspMc.isAnimationRunning()) {
					AspMc.setFlippedHorizontal(false);
					AspMc.setPosition(rigthPosX, CurY);
					CurX = rigthPosX;
					AspMc.setFlippedHorizontal(false);
					setAnim(SPR_ANIME_IDLE, 0);
					isSwap = false;
					// RctMc.setWidth((AspMc.getWidth())-(AspMc.getWidth()/3));
					RctMc.setX(AspMc.getX());

				}
				break;
		}
	}

	public void setVisible(boolean bol) {
		// spr.setVisible(bol);
		this.AspMc.setVisible(bol);
	}

	public static void setAnim(int anim, boolean loop) {
		AspMc.animate(SPR_MC_SPEED[anim], SPR_MC_ANIM_FRAME[anim], loop);
	}

	public static void setAnim(int anim, int count) {
		AspMc.animate(SPR_MC_SPEED[anim], SPR_MC_ANIM_FRAME[anim], count);
	}

	public AnimatedSprite getAspMc() {
		return AspMc;
	}

	public void setAspMc(AnimatedSprite aspMc) {
		AspMc = aspMc;
	}

	public float getCurX() {
		return CurX;
	}

	public void setCurX(float curX) {
		CurX = curX;
	}

	public float getCurY() {
		return CurY;
	}

	public void setCurY(float curY) {
		CurY = curY;
	}

	public Rectangle getRctMc() {
		return RctMc;
	}

	public void setRctMc(Rectangle rctMc) {
		RctMc = rctMc;
	}

	public int getCurrentPos() {
		return CurrentPos;
	}

	public void setCurrentPos(int currentPos) {
		CurrentPos = currentPos;
	}

	public int getCurrentState() {
		return CurrentState;
	}

	public void setCurrentState(int currentState) {
		CurrentState = currentState;
	}

	public int getLeftPosX() {
		return leftPosX;
	}

	public void setLeftPosX(int leftPosX) {
		this.leftPosX = leftPosX;
	}

	public int getRigthPosX() {
		return rigthPosX;
	}

	public float getRctX() {
		getRctX = RctMc.getX();
		return getRctX;
	}

	public void setGetRctX(float getRctX) {
		this.getRctX = getRctX;
	}

	public void setRigthPosX(int rigthPosX) {
		this.rigthPosX = rigthPosX;
	}

	public static boolean isSwap() {
		return isSwap;
	}

	public static boolean isAnimationRunning() {
		if (AspMc.isAnimationRunning()) {
			return true;
		} else {
			return false;
		}
	}

	public static void setSwap(boolean isSwap) {
		Entity_Mc.isSwap = isSwap;
	}

}
